using System;
using NXDO.Data.Linq;
using NXDO.Data.Extension;
using NXDO.Data.DbClient;

namespace TDM.DbData.DataEntity
{
	public enum/*static class*/ AllTableName
	{
		Customer, //public static string Table_Customer{ get { return "Customer";} }
		TestTask, //public static string Table_TestTask{ get { return "TestTask";} }
		DaPosition, //public static string Table_DaPosition{ get { return "DaPosition";} }
		DaRole, //public static string Table_DaRole{ get { return "DaRole";} }
		DaUser, //public static string Table_DaUser{ get { return "DaUser";} }
		Department, //public static string Table_Department{ get { return "Department";} }
		DeptUser, //public static string Table_DeptUser{ get { return "DeptUser";} }
		TestLaserData, //public static string Table_TestLaserData{ get { return "TestLaserData";} }
		TestLaserPara, //public static string Table_TestLaserPara{ get { return "TestLaserPara";} }
		TestLaserResult, //public static string Table_TestLaserResult{ get { return "TestLaserResult";} }
		TestProject, //public static string Table_TestProject{ get { return "TestProject";} }
		TestResultFile, //public static string Table_TestResultFile{ get { return "TestResultFile";} }
		TestSubTask, //public static string Table_TestSubTask{ get { return "TestSubTask";} }
		DataExport,
		DataImport,
        BaseEnergyDistribution,
        BaseCarryDevice,
        TestTaskFile
    }

	#region linq interface
	/// <summary>
	/// Linq上下文特定连接查询环境
	/// </summary>
	public interface IAllLinqContext
	{
		/// <summary>
		/// Customer的Linq查询
		/// <para>var rs = from c in Customer where ... select c</para>
		/// </summary>
		ILinq<Customer> Customer { get; }

		/// <summary>
		/// TestTask的Linq查询
		/// <para>var rs = from t in TestTask where ... select t</para>
		/// </summary>
		ILinq<TestTask> TestTask { get; }

		/// <summary>
		/// DaPosition的Linq查询
		/// <para>var rs = from d in DaPosition where ... select d</para>
		/// </summary>
		ILinq<DaPosition> DaPosition { get; }

		/// <summary>
		/// DaRole的Linq查询
		/// <para>var rs = from d in DaRole where ... select d</para>
		/// </summary>
		ILinq<DaRole> DaRole { get; }

		/// <summary>
		/// DaUser的Linq查询
		/// <para>var rs = from d in DaUser where ... select d</para>
		/// </summary>
		ILinq<DaUser> DaUser { get; }

		/// <summary>
		/// Department的Linq查询
		/// <para>var rs = from d in Department where ... select d</para>
		/// </summary>
		ILinq<Department> Department { get; }

		/// <summary>
		/// DeptUser的Linq查询
		/// <para>var rs = from d in DeptUser where ... select d</para>
		/// </summary>
		ILinq<DeptUser> DeptUser { get; }

		/// <summary>
		/// TestLaserData的Linq查询
		/// <para>var rs = from t in TestLaserData where ... select t</para>
		/// </summary>
		ILinq<TestLaserData> TestLaserData { get; }

		/// <summary>
		/// TestLaserPara的Linq查询
		/// <para>var rs = from t in TestLaserPara where ... select t</para>
		/// </summary>
		ILinq<TestLaserPara> TestLaserPara { get; }

		/// <summary>
		/// TestLaserResult的Linq查询
		/// <para>var rs = from t in TestLaserResult where ... select t</para>
		/// </summary>
		ILinq<TestLaserResult> TestLaserResult { get; }

		/// <summary>
		/// TestProject的Linq查询
		/// <para>var rs = from t in TestProject where ... select t</para>
		/// </summary>
		ILinq<TestProject> TestProject { get; }

		/// <summary>
		/// TestResultFile的Linq查询
		/// <para>var rs = from t in TestResultFile where ... select t</para>
		/// </summary>
		ILinq<TestResultFile> TestResultFile { get; }

        /// <summary>
        /// TestSubTask的Linq查询
        /// <para>var rs = from t in TestSubTask where ... select t</para>
        /// </summary>
        ILinq<TestSubTask> TestSubTask { get; }
        
    }
	#endregion

	#region linq context
	/// <summary>
	/// Linq上下文默认连接查询环境
	/// </summary>
	public sealed class AllLinqContext : IAllLinqContext
	{
		#region ctor/static
        private AllLinqContext() { }
        private ILinqProvider Provider { get; set; }

        /// <summary>
        /// 通过数据库连接获取特定连接的Linq上下文查询环境.
        /// </summary>
        /// <param name="dbConnection">数据库连接</param>
        /// <returns>特定连接查询环境</returns>
        public static IAllLinqContext CreateContext(AnyDbConnection dbConnection)
        {
            if (dbConnection == null)
                throw new ArgumentNullException("dbConnection");
            return new AllLinqContext { Provider = dbConnection.CreateDbLinqProvider() };
        }

        #region 获取查询体
        static ILinq<T> GetQueryable<T>(ILinqProvider provider = null) where T : NXDO.Data.Entity, new()
        {
            if (provider == null)
                return new T().DBLinq();
            return provider.GetQueryableEntity<T>();
        }
        #endregion
        #endregion

		#region Customer
		ILinq<Customer> IAllLinqContext.Customer
		{
			get { return AllLinqContext.GetQueryable<Customer>(this.Provider); } 
		}

		/// <summary>
		/// Customer的Linq查询
		/// <para>var rs = from c in Customer where ... select c</para>
		/// </summary>
		public static ILinq<Customer> Customer
		{
			get { return _Customer ?? (_Customer = AllLinqContext.GetQueryable<Customer>()); }
		}static ILinq<Customer> _Customer;
		#endregion

		#region TestTask
		ILinq<TestTask> IAllLinqContext.TestTask
		{
			get { return AllLinqContext.GetQueryable<TestTask>(this.Provider); } 
		}

		/// <summary>
		/// TestTask的Linq查询
		/// <para>var rs = from t in TestTask where ... select t</para>
		/// </summary>
		public static ILinq<TestTask> TestTask
		{
			get { return _TestTask ?? (_TestTask = AllLinqContext.GetQueryable<TestTask>()); }
		}static ILinq<TestTask> _TestTask;
		#endregion

		#region DaPosition
		ILinq<DaPosition> IAllLinqContext.DaPosition
		{
			get { return AllLinqContext.GetQueryable<DaPosition>(this.Provider); } 
		}

		/// <summary>
		/// DaPosition的Linq查询
		/// <para>var rs = from d in DaPosition where ... select d</para>
		/// </summary>
		public static ILinq<DaPosition> DaPosition
		{
			get { return _DaPosition ?? (_DaPosition = AllLinqContext.GetQueryable<DaPosition>()); }
		}static ILinq<DaPosition> _DaPosition;
		#endregion

		#region DaRole
		ILinq<DaRole> IAllLinqContext.DaRole
		{
			get { return AllLinqContext.GetQueryable<DaRole>(this.Provider); } 
		}

		/// <summary>
		/// DaRole的Linq查询
		/// <para>var rs = from d in DaRole where ... select d</para>
		/// </summary>
		public static ILinq<DaRole> DaRole
		{
			get { return _DaRole ?? (_DaRole = AllLinqContext.GetQueryable<DaRole>()); }
		}static ILinq<DaRole> _DaRole;
		#endregion

		#region DaUser
		ILinq<DaUser> IAllLinqContext.DaUser
		{
			get { return AllLinqContext.GetQueryable<DaUser>(this.Provider); } 
		}

		/// <summary>
		/// DaUser的Linq查询
		/// <para>var rs = from d in DaUser where ... select d</para>
		/// </summary>
		public static ILinq<DaUser> DaUser
		{
			get { return _DaUser ?? (_DaUser = AllLinqContext.GetQueryable<DaUser>()); }
		}static ILinq<DaUser> _DaUser;
		#endregion

		#region Department
		ILinq<Department> IAllLinqContext.Department
		{
			get { return AllLinqContext.GetQueryable<Department>(this.Provider); } 
		}

		/// <summary>
		/// Department的Linq查询
		/// <para>var rs = from d in Department where ... select d</para>
		/// </summary>
		public static ILinq<Department> Department
		{
			get { return _Department ?? (_Department = AllLinqContext.GetQueryable<Department>()); }
		}static ILinq<Department> _Department;
		#endregion

		#region DeptUser
		ILinq<DeptUser> IAllLinqContext.DeptUser
		{
			get { return AllLinqContext.GetQueryable<DeptUser>(this.Provider); } 
		}

		/// <summary>
		/// DeptUser的Linq查询
		/// <para>var rs = from d in DeptUser where ... select d</para>
		/// </summary>
		public static ILinq<DeptUser> DeptUser
		{
			get { return _DeptUser ?? (_DeptUser = AllLinqContext.GetQueryable<DeptUser>()); }
		}static ILinq<DeptUser> _DeptUser;
		#endregion

		#region TestLaserData
		ILinq<TestLaserData> IAllLinqContext.TestLaserData
		{
			get { return AllLinqContext.GetQueryable<TestLaserData>(this.Provider); } 
		}

		/// <summary>
		/// TestLaserData的Linq查询
		/// <para>var rs = from t in TestLaserData where ... select t</para>
		/// </summary>
		public static ILinq<TestLaserData> TestLaserData
		{
			get { return _TestLaserData ?? (_TestLaserData = AllLinqContext.GetQueryable<TestLaserData>()); }
		}static ILinq<TestLaserData> _TestLaserData;
		#endregion

		#region TestLaserPara
		ILinq<TestLaserPara> IAllLinqContext.TestLaserPara
		{
			get { return AllLinqContext.GetQueryable<TestLaserPara>(this.Provider); } 
		}

		/// <summary>
		/// TestLaserPara的Linq查询
		/// <para>var rs = from t in TestLaserPara where ... select t</para>
		/// </summary>
		public static ILinq<TestLaserPara> TestLaserPara
		{
			get { return _TestLaserPara ?? (_TestLaserPara = AllLinqContext.GetQueryable<TestLaserPara>()); }
		}static ILinq<TestLaserPara> _TestLaserPara;
		#endregion

		#region TestLaserResult
		ILinq<TestLaserResult> IAllLinqContext.TestLaserResult
		{
			get { return AllLinqContext.GetQueryable<TestLaserResult>(this.Provider); } 
		}

		/// <summary>
		/// TestLaserResult的Linq查询
		/// <para>var rs = from t in TestLaserResult where ... select t</para>
		/// </summary>
		public static ILinq<TestLaserResult> TestLaserResult
		{
			get { return _TestLaserResult ?? (_TestLaserResult = AllLinqContext.GetQueryable<TestLaserResult>()); }
		}static ILinq<TestLaserResult> _TestLaserResult;
		#endregion

		#region TestProject
		ILinq<TestProject> IAllLinqContext.TestProject
		{
			get { return AllLinqContext.GetQueryable<TestProject>(this.Provider); } 
		}

		/// <summary>
		/// TestProject的Linq查询
		/// <para>var rs = from t in TestProject where ... select t</para>
		/// </summary>
		public static ILinq<TestProject> TestProject
		{
			get { return _TestProject ?? (_TestProject = AllLinqContext.GetQueryable<TestProject>()); }
		}static ILinq<TestProject> _TestProject;
		#endregion

		#region TestResultFile
		ILinq<TestResultFile> IAllLinqContext.TestResultFile
		{
			get { return AllLinqContext.GetQueryable<TestResultFile>(this.Provider); } 
		}

		/// <summary>
		/// TestResultFile的Linq查询
		/// <para>var rs = from t in TestResultFile where ... select t</para>
		/// </summary>
		public static ILinq<TestResultFile> TestResultFile
		{
			get { return _TestResultFile ?? (_TestResultFile = AllLinqContext.GetQueryable<TestResultFile>()); }
		}static ILinq<TestResultFile> _TestResultFile;
        #endregion

        #region TestSubTask
        ILinq<TestSubTask> IAllLinqContext.TestSubTask
        {
            get { return AllLinqContext.GetQueryable<TestSubTask>(this.Provider); }
        }

        /// <summary>
        /// TestSubTask的Linq查询
        /// <para>var rs = from t in TestSubTask where ... select t</para>
        /// </summary>
        public static ILinq<TestSubTask> TestSubTask
        {
            get { return _TestSubTask ?? (_TestSubTask = AllLinqContext.GetQueryable<TestSubTask>()); }
        }
        static ILinq<TestSubTask> _TestSubTask;
        #endregion
    }
    #endregion

}
